/**
 * Created by maiseries on 2017/9/25.
 */
import React from 'react';
import {
    Platform,
    Dimensions,
    PixelRatio,
    StyleSheet
} from 'react-native';

const {width, height} = Dimensions.get('window');
const designWidth = 750, designHeight = 1334, designPPI = 2;
const widthScale = width / ( designWidth / designPPI );
const heightScale = height / ( designHeight / designPPI );

export default class Layout {
    /**
     * 点击事件透明度
     * @type {number}
     */
    static TOUCH_OPACITY_ACTIVE = 0.8;
    /**
     * 下拉刷新延迟时间 ms
     * @type {number}
     */
    static REFRESH_DELAY_TIME = 600;
    /**
     * 状态栏高度
     * @type {number}
     */
    static STATUS_BAR_HEIGHT = Platform.OS === 'ios' ? 20 : Platform.Version >= 21 ? 25 : 0;
    /**
     * 导航栏高度
     * @type {number}
     */
    static NAV_BAR_HEIGHT = Platform.OS === 'ios' ? 44 : 56;
    /**
     * 1px最细线
     */
    static LINE_WIDTH = StyleSheet.hairlineWidth;
    /**
     * client最大宽度
     * @type {Object.width}
     */
    static MAX_WIDTH = width;
    /**
     * client最大高度
     * @type {Object.height}
     */
    static MAX_HEIGHT = height;
    /**
     * 主背景颜色
     * @type {string}
     */
    static MAIN_BACKGROUND_COLOR = '#f4f3ef';
    /**
     * 禁用颜色
     * @type {string}
     */
    static DISABLED_COLOR = '#c1c1c1';
    /**
     * 主字体颜色
     * @type {string}
     */
    static MAIN_FONT_COLOR = '#333855';
    /**
     * 表单字体颜色
     * @type {string}
     */
    static FORM_FONT_COLOR = '#666';
    /**
     * 辅字体颜色
     * @type {string}
     */
    static AUX_FONT_COLOR = '#e0d0af';
    /**
     * 表单字体辅助颜色
     * @type {string}
     */
    static FORM_AUX_FONT_COLOR = '#c2c2c2';
    /**
     * 主颜色
     * @type {string}
     */
    static MAIN_COLOR = '#e0b161';
    /**
     * 主辅助色
     * @type {string}
     */
    static MAIN_AUX_COLOR = '#333855';
    /**
     * 主边框颜色
     * @type {string}
     */
    static MAIN_BORDER_COLOR = '#f1f1f1';
    static MAIN_BORDER_COLOR_C1 = '#c1c1c1';
    /**
     * 横向间隙
     */
    static GAP_HORIZONTAL_LARGE = 40 / designWidth * width;
    static GAP_HORIZONTAL_MID = 20 / designWidth * width;
    static GAP_HORIZONTAL_SMALL = 12 / designWidth * width;
    /**
     * 纵向间隙
     */
    static GAP_VERTICAL_LARGE = 44 / designHeight * height;
    static GAP_VERTICAL_MID = 24 / designHeight * height;
    static GAP_VERTICAL_SMALL = 12 / designHeight * height;
    /**
     * 底部TAB高度
     */
    static BOTTOM_TAB_HEIGHT = 139 / designHeight * height;
    static BOTTOM_TAB_HEIGHT_ANDROID = 223 / designHeight * height;
    /**
     * 宽度转换
     * @param w
     * @returns {number}
     */
    static width(w) {
        return w / designWidth * width;
    }

    /**
     * 高度转换
     * @param h
     * @returns {number}
     */
    static height(h) {
        return h / designHeight * height;
    }

    static heightToFixed(h) {
        return (h / designHeight * height).toFixed(0) >>> 0;
    }

    /**
     * 字体转换
     * @param f
     * @returns {number}
     */
    static font(f) {
        const scale = Math.min(widthScale, heightScale);
        return Math.round(f * scale / designPPI);
    }
}